package com.ccc.demoboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccc.demoboot.common.R;
import com.ccc.demoboot.pojo.*;
import com.ccc.demoboot.service.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author wz
 * @Date 2024/5/23 11:36
 * @PackageName:com.ccc.demoboot.controller
 * @ClassName: SysuserMidroleController
 */
@RequestMapping("/sysuserMidrole")
@RestController
public class SysuserMidroleController {

    @Autowired
    SysusermidroleService sysusermidroleService;
    @Autowired
    SysuserService sysuserService;
    @Autowired
    JobtypeService jobtypeService;
    @Autowired
    PostService postService;
    @Autowired
    DepartmentService departmentService;

    @Autowired
    RoleService roleservice;

    /**
     * 查询所有
     *
     * @param page
     * @return
     */
    @GetMapping("/select/{page}")
    public R select(@PathVariable("page") int page) {
        PageHelper.startPage(page, 5);//第一个参数表示第几页,第二个参数表示每页的条数
        List<Role> list = this.sysusermidroleService.select();
        PageInfo<Role> menuPageInfo = new PageInfo<>(list);
        return new R().add("pageInfo", menuPageInfo);
    }

    /**
     * 根据条件查询
     * @param role
     * @return
     */
    @PostMapping("/selectTj")
    public R selectTj(@RequestBody Role role){
        List<Role> list=this.sysusermidroleService.selectTj(role);
        return new R().add("list",list);

    }

    /**
     * 根据角色id查询所属部门岗位工种
     *
     * @param sysusermidrole
     * @return
     */
    @PostMapping("/selectRoleid")
    public R selectRoleid(@RequestBody Sysusermidrole sysusermidrole) {

        List<Map<String, Object>> listJob = this.sysusermidroleService.selectRoleidJobtype(sysusermidrole.getRoleid());
        List<Map<String, Object>> listDep = this.sysusermidroleService.selectRoleidDepartment(sysusermidrole.getRoleid());
        List<Map<String, Object>> listPos = this.sysusermidroleService.selectRoleidPost(sysusermidrole.getRoleid());
        List<Map<String, Object>> listUser = this.sysusermidroleService.selectRoleidUser(sysusermidrole.getRoleid());

        return new R().add("listJob",listJob).add("listDep",listDep).add("listPos",listPos).add("listUser",listUser);
    }

    /**
     * 删除角色拥有
     * @param sysusermidrole
     * @return
     */
    @PostMapping("/delUserByid")
    public R delUserByid(@RequestBody Sysusermidrole sysusermidrole) {
        boolean remove = this.sysusermidroleService.removeById(sysusermidrole.getId());
        return new R().add("remove",remove);
    }


    /**
     * 添加角色部门权限
     * @param sysusermidrole
     * @return
     */
    @PostMapping("/addcheckListdep")
    public R addCheckListDep(@RequestBody Sysusermidrole sysusermidrole){
        boolean save =  this.sysusermidroleService.addCheckListDep(sysusermidrole);
        return new R().add("save",save);
    }


    /**
     * 删除角色部门权限
     * @param sysusermidrole
     */
    @PostMapping("/delcheckListdep")
    public R delCheckListDep(@RequestBody Sysusermidrole sysusermidrole){

        boolean save =  this.sysusermidroleService.delCheckListDep(sysusermidrole);
        return new R().add("save",save);
    }

    /**
     * 修改ids
     * @param maps
     * @return
     */
    @PostMapping("/upsysuserMidrole")
    public R upSysUserMidrole(@RequestBody Map<String,Object> maps){
        int roleid= (int) maps.get("roleid");
        Object ids = maps.get("ids");
        boolean remove=  this.sysusermidroleService.delId(ids.toString());
        boolean save =  this.sysusermidroleService.addMidrole(roleid,ids.toString());
        return new R().add("save",save).add("remove", remove);
    }


}
